package com.attendance.www.hr.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.attendance.www.hr.beans.SalaryRuleBean;
import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.ISalaryRuleService;
import com.zhangkongli.frame.core.ResultMap;

/**
 * 工资审批规则
 * @version 2017/04/09
 * @author 邢聪聪
 *
 */
@Controller
@RequestMapping("/salaryApprovalRule")
public class SalaryRuleController {
		@Resource
		private ISalaryRuleService salaryRuleService;
		
		/**
		 * 查询工资审批规则
		 * @param request
		 * @return
		 */
		@RequestMapping(value="/getSalaryApprovalRuleList.do",method={RequestMethod.POST,RequestMethod.GET})
		@ResponseBody
		public Object getSalaryRuleList(HttpServletRequest request){
			return ResultMap.success(salaryRuleService.getSalaryRuleList());
		}
		
		/**
		 * 新增工资审批规则
		 * @param request
		 * @param salaryRuleBean
		 * @return
		 */
		@RequestMapping(value="/saveSalaryRule.do",method={RequestMethod.POST,RequestMethod.GET})
		@ResponseBody
		public Object saveSalaryRule(HttpServletRequest request,@RequestBody SalaryRuleBean salaryRuleBean){
	
			if(salaryRuleBean!=null){
				if(salaryRuleService.saveSalaryRule(salaryRuleBean)){
					return ResultMap.success();
				}else{
							throw new ResultFaultException("0_00007");
				}
			}
			throw new ResultFaultException("0_00001");		
		}
		
		/**
		 * 修改工资审批规则			
		 * @param request
		 * @param salaryRuleBean
		 * @return
		 */
		@RequestMapping(value="/updateSalaryRule.do",method={RequestMethod.POST,RequestMethod.GET})
		@ResponseBody
		public Object updateSalaryRule(HttpServletRequest request,@RequestBody SalaryRuleBean salaryRuleBean){
			
			if (salaryRuleBean.getSalaryRuleId()==null) {
				throw new ResultFaultException("0_00001");
			}
			if(salaryRuleService.updateSalaryRule(salaryRuleBean)){
				return ResultMap.success();
			}else{
				throw new ResultFaultException("0_00008");
			}
		}
		
		/**
		 * 删除工资审批规则接口			
		 * @param request
		 * @return
		 */
		@RequestMapping(value = "/deleteSalaryRule.do", method = { RequestMethod.POST, RequestMethod.GET })
		@ResponseBody
		public Object deleteSalaryRule(HttpServletRequest request) {
			String salaryRuleIdString = request.getParameter("salaryRuleId");
			if (StringUtils.isBlank(salaryRuleIdString)) {
				throw new ResultFaultException("0_00001");
			}
			Integer salaryRuleId = Integer.valueOf(salaryRuleIdString);
			return ResultMap.success(salaryRuleService.deleteSalaryRule(salaryRuleId));
		}
		
}
